<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <script>
        // 1.获取到当前时间戳
        let date = new Date()
        console.log(date);
        let time = getTime(date)
        console.log(time);
        

        // 2.时间戳格式转换函数
        function getTime(time) {
        let YYYY = time.getFullYear() // 年
        let MM = time.getMonth() + 1  // 月
        let DD = time.getDate()        // 日
        let HH = time.getHours()       // 时
        let mm = time.getMinutes()    // 分
        let ss = time.getSeconds()    // 秒

        const shijian = YYYY + '年' + MM + '月' + DD + '日' + HH + '时' + mm + '分' + ss + '秒'
        return shijian
        }
    </script>
</body>
</html>